﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentsPrenseLog.Extentions
{
    public static class IOHelperExtentions
    {
        public static float ReadFloatFromConsole(String welcomeText)
        {
            float parsedValue;
            while (true)
            {
                Console.WriteLine(welcomeText);
                String floatToParse = Console.ReadLine();
                if (float.TryParse(floatToParse, out parsedValue))
                {
                    break;
                }
                Console.WriteLine("Float has been entered in wrong format. Please enter again");
            }
            return parsedValue;
        }


        public static DateTime ReadDateFromConsole(String welcomeText,String format)
        {
            DateTime parsedDate;
            while (true)
            {
                Console.WriteLine(welcomeText);
                String dateToParse = Console.ReadLine();

                if (DateTime.TryParseExact(dateToParse, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedDate))
                {
                    break;
                }
                Console.WriteLine("Date has been entered in wrong format. Please enter again");
            }
            return parsedDate;
        }
    }
}
